package flc.ast.widget.time;

import android.annotation.SuppressLint;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.graphics.Color;
import android.widget.RemoteViews;

import com.blankj.utilcode.util.TimeUtils;

import java.text.SimpleDateFormat;

import flc.ast.R;
import flc.ast.utils.AppSpUtils;
import stark.common.basic.utils.BitmapUtil;

public class Time6Widget extends BaseTimeWidget {


    public Time6Widget(int appWidgetId) {
        super(appWidgetId);
    }

    @Override
    protected void onUpdate(Context context) {
        @SuppressLint("RemoteViewLayout") RemoteViews remoteViews =
                new RemoteViews(context.getPackageName(), R.layout.widget_time6);
        //准备数据
        String date = TimeUtils.getNowString(new SimpleDateFormat("MM月dd日"));
        String time1 = TimeUtils.getNowString(new SimpleDateFormat("HH"));
        String time2 = TimeUtils.getNowString(new SimpleDateFormat("mm"));
        String week = TimeUtils.getNowString(new SimpleDateFormat("EEEE"));
        //更新显示数据
        remoteViews.setTextViewText(R.id.tvTime6Week, week);
        remoteViews.setTextViewText(R.id.tvTime6Date, date);
        String time6Color = AppSpUtils.getTime6Color();
        remoteViews.setImageViewBitmap(R.id.tvTime6TimeH, BitmapUtil.text2BmpWithAssetFont(context, time1,
                Color.parseColor(time6Color), 26, "font/ziti3.ttf"));
        remoteViews.setImageViewBitmap(R.id.tvTime6TimeM, BitmapUtil.text2BmpWithAssetFont(context, time2,
                Color.parseColor(time6Color), 26, "font/ziti3.ttf"));
        remoteViews.setImageViewBitmap(R.id.tvTime6Dot, BitmapUtil.text2BmpWithAssetFont(context, ":",
                Color.parseColor(time6Color), 26, "font/ziti3.ttf"));
        remoteViews.setTextColor(R.id.tvTime6Week, Color.parseColor(time6Color));

        remoteViews.setInt(R.id.llTime6Bg, "setBackgroundColor", AppSpUtils.getTime6Bg());

        AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
    }
}